#version 450

struct Circle {
	vec2 position;
	float radius;
	float padding;
	vec4 color;
};

layout(set = 0, binding = 0) buffer Circles {
	Circle circles[];
};

layout(set = 1, binding = 0) uniform MVP {
	mat4 model;
	mat4 view;
	mat4 proj;
	vec2 offset;
};
layout(set = 1, binding = 1) uniform CircleParams {
	float thickness;
};

layout(location = 0) out vec4 fragColor;
layout(location = 1) flat out vec2 center;
layout(location = 2) flat out float circleRadius;
layout(location = 3) flat out float lineThickness;

uint indices[6] = { 0, 1, 2, 3, 2, 1 };

void main() {
	uint index = gl_VertexIndex / 6;
	Circle circle = circles[index];
	fragColor = circle.color;
	circleRadius = circle.radius;
	lineThickness = thickness;
	center = circle.position + circle.radius;
	float diameter = circle.radius * 2;
    vec2 squareCoords[4] = {
        circle.position,
        { circle.position.x + diameter, circle.position.y },
        { circle.position.x, circle.position.y + diameter },
        { circle.position.x + diameter, circle.position.y + diameter },
    };
	center += offset;
	gl_Position = proj * view * model * vec4(squareCoords[indices[gl_VertexIndex % 6]], 0.0, 1.0);
}